package com.web.dao.impl;

import com.web.dao.StudentDAO;
import com.web.entity.Student;
import com.web.util.JDBCUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 学生数据访问实现类
 */
@Repository
public class StudentDAOImpl implements StudentDAO {
    @Override
    public List<Student> selectAllStudents() {
        return JDBCUtils.query(Student.class,"select * from student");
    }

    @Override
    public List<Student> selectStudentPage(int start, int len) {
        return JDBCUtils.query(Student.class,
                "select * from student limit ?,?",start,len);
    }

    @Override
    public int selectStudentCount() {
        return JDBCUtils.queryCount("select count(*) from student");
    }

    @Override
    public void insertStudent(Student student) {
        JDBCUtils.update(
                "insert into student(name,age,gender,cellphone,address) values(?,?,?,?,?)",
                student.getName(),student.getAge(),student.getGender(),student.getCellphone(),student.getAddress());
    }

    @Override
    public void updateStudent(Student student) {
        JDBCUtils.update(
                "update student set name=?,age=?,gender=?,cellphone=?,address=? where id=?",
                student.getName(),student.getAge(),student.getGender(),student.getCellphone(),student.getAddress(),student.getId());

    }

    @Override
    public void deleteStudent(int id) {
        JDBCUtils.update("delete from student where id =?",id);
    }
}
